package com.xiaoyao.myframeapp.utils.Glide;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Matrix;

import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;
import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;
import com.xiaoyao.myframeapp.utils.L;

/**
 * @Author xiaoyao
 * @Email xiao80206040@qq.com
 * @Explain Glide 照片墙
 * @Created by Administrator on 2017/3/31 0031 08:57
 */
public class DunamicPhotoWallTransform extends BitmapTransformation {
    //TODO Glide 动态 照片
    private static int spanCount = 3;//TODO 按照宽度
//    private static ImageView iv;
//    private static InfoHint infoHint;

    public DunamicPhotoWallTransform(Context context) {
        super(context);
    }


    public DunamicPhotoWallTransform(Context context, int spanCount/*, ImageView iv, InfoHint infoHint*/) {
        super(context);
        DunamicPhotoWallTransform.spanCount = spanCount;
//        DunamicPhotoWallTransform.iv = iv;
//        DunamicPhotoWallTransform.infoHint = infoHint;
    }

    @Override
    protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {

        L.i("aaa");
        return roundCrop_w(pool, toTransform);
    }

    //TODO 宽
    private static Bitmap roundCrop_w(BitmapPool pool, Bitmap resource) {

//        L.e("h=" + resource.getHeight());
//        L.e("w=" + resource.getWidth());
        int height = resource.getHeight();
        int weight = resource.getWidth();

        float ratio = (float) spanCount / weight;

        //TODO 获取一个长宽
//        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) iv.getLayoutParams();
//        params.weight = spanCount;
//        params.height = (int) (height / ratio);
//        iv.setLayoutParams(params);


//        int wt = (int) (weight * ratio);
//        int ht = (int) (height * ratio);
//
//        infoHint.setOnClickListener(wt, ht);
        Matrix matrix = new Matrix();
//        matrix.postScale(0.8f, 0.8f); //长和宽放大缩小的比例
        matrix.postScale(ratio, ratio); //长和宽放大缩小的比例
        Bitmap resizeBmp = Bitmap.createBitmap(resource, 0, 0, resource.getWidth(), resource.getHeight(), matrix, true);
        return resizeBmp;

    }

    @Override
    public String getId() {
//        return getClass().getName() + Math.round(radius);

        return getClass().getSimpleName();
    }


    /**
     * 设置点赞的动画,通过接口产生信息回调
     */
    public interface InfoHint {


        void setOnClickListener(int weight, int height);
    }

}